var pageType;// 页面类型：区域、楼层、店铺
var isFirstLoad;// 是否是第一次加载，用来替换日期控件
var p_type;// 记录当前选中的日期类型，点击查询按钮时根据此类型动态加载指标说明
Array.prototype.indexOf = function(val) {
	for ( var i = 0; i < this.length; i++) {
		if (this[i] == val)
			return i;
	}
	return -1;
};
Array.prototype.remove = function(val) {
	var index = this.indexOf(val);
	if (index > -1) {
		this.splice(index, 1);
	}
};
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
function showTimePicker() {
	var endDate = new Date();// 当前时间
	endDate = endDate.getFullYear() + "-" + (endDate.getMonth() + 1) + "-"
			+ endDate.getDate();
	var startDate = (new Date());
	startDate.setDate(startDate.getDate() - 30);// 前一个月时间
	startDate = startDate.getFullYear() + "-" + (startDate.getMonth() + 1)
			+ "-" + startDate.getDate();
	var startMonth = new Date();
	startMonth.setDate(startMonth.getDate() - 90);
	startMonth = startMonth.getFullYear() + "-" + (startMonth.getMonth() + 1)
			+ "-" + startMonth.getDate();
	var startYear = new Date();
	startYear.setFullYear(startYear.getFullYear() - 3);
	startYear = startYear.getFullYear() + "-" + (startYear.getMonth() + 1)
			+ "-" + startYear.getDate();
	var dateObj = {
		theme : 'ta', // 日期选择器TA主题
		autoCommit : true, // 自动提交，完成日期初始化，以及图表的展示拉取
		isTodayValid : true,
		startDate : startDate,
		endDate : endDate,
		needCompare : true,
		startCompareDate : '',
		endCompareDate : '',
		singleCompare : false,
		defaultText : ' 至 ',
		autoSubmit : false,
		shortOpr : false,
		target : 'datePicker',
		calendars : 2,
		inputTrigger : 'input_trigger',
		compareCheckboxId : false,
		success : function(obj) {
			if (!isFirstLoad) {
				showLoading();
				if (pageType == 1) {
					if ($("#qy_time").val() != "")// 处于日期选择框时
		{
			$('#qy_startDate').attr("value", $('#startDate').val());
			$('#qy_endDate').attr("value", $('#endDate').val());
			getspan('day_0');
		}
	} else if (pageType == 2) {
		if ($("#lc_time").val() != "")// 处于日期选择框时
		{
			$('#lc_startDate').attr("value", $('#startDate').val());
			$('#lc_endDate').attr("value", $('#endDate').val());
			getspan('day_0');
		}
	} else if (pageType == 3) {
		if ($("#dp_time").val() != "")// 处于日期选择框时
		{
			$('#dp_startDate').attr("value", $('#startDate').val());
			$('#dp_endDate').attr("value", $('#endDate').val());
			getspan('day_0');
		}
	} else if (pageType == 4) {
		if ($("#td_time").val() != "")// 处于日期选择框时
		{
			$('#td_startDate').attr("value", $('#startDate').val());
			$('#td_endDate').attr("value", $('#endDate').val());
			getspan('day_0');
		}
	}
}
isFirstLoad = false;
}
	};
	new pickerDateRange("date", dateObj)
}

function changeTime(type) {
	isFirstLoad = true;
	$("#shijianduibi").removeClass("lxxzselected");
	if (type == "Day") {
		$('#qy_date').attr("value", "day");
		$('#qy_time').attr("value", "1");
		$('#lc_date').attr("value", "day");
		$('#lc_time').attr("value", "1");
		$('#dp_date').attr("value", "day");
		$('#dp_time').attr("value", "1");
		$('#td_date').attr("value", "day");
		$('#td_time').attr("value", "1");
		$("td[id^='day_']").show();
		$("td[id^='day_']").removeClass("lxxzselected");
		// $("#day_1").addClass("lxxzselected");
		$("td[id^='week_']").hide();
		$("td[id^='month_']").hide();
		$("td[id^='year_']").hide();
		$("td[id^='hour_']").hide();

		$("#rzyn td").removeClass("lxxzselected");
		$("#Day").addClass("lxxzselected");
		clearRiQiKongjian();
		showTimePicker();
		getspan('day_1');
	}
	if (type == "Week") {
		$('#qy_date').attr("value", "week");
		$('#qy_time').attr("value", "4");
		$('#lc_date').attr("value", "week");
		$('#lc_time').attr("value", "4");
		$('#dp_date').attr("value", "week");
		$('#dp_time').attr("value", "4");
		$('#td_date').attr("value", "week");
		$('#td_time').attr("value", "4");
		$("td[id^='day_']").hide();
		$("td[id^='week_']").removeClass("lxxzselected");
		// $("#week_4").addClass("lxxzselected");
		$("td[id^='week_']").show();
		$("td[id^='month_']").hide();
		$("td[id^='year_']").hide();
		$("td[id^='hour_']").hide();

		$("#rzyn td").removeClass("lxxzselected");
		$("#Week").addClass("lxxzselected");
		clearRiQiKongjian();
		showTimePicker();
		getspan('week_4');
	}
	if (type == "Month") {
		$('#qy_date').attr("value", "month");
		$('#qy_time').attr("value", "3");
		$('#lc_date').attr("value", "month");
		$('#lc_time').attr("value", "3");
		$('#dp_date').attr("value", "month");
		$('#dp_time').attr("value", "3");
		$('#td_date').attr("value", "month");
		$('#td_time').attr("value", "3");
		$("td[id^='day_']").hide();
		$("td[id^='month_']").removeClass("lxxzselected");
		// $("#month_3").addClass("lxxzselected");
		$("td[id^='week_']").hide();
		$("td[id^='month_']").show();
		$("td[id^='year_']").hide();
		$("td[id^='hour_']").hide();

		$("#rzyn td").removeClass("lxxzselected");
		$("#Month").addClass("lxxzselected");
		clearRiQiKongjian();
		showTimePicker();
		getspan('month_3');
	}
	if (type == "Year") {
		$('#qy_date').attr("value", "year");
		$('#qy_time').attr("value", "3");
		$('#lc_date').attr("value", "year");
		$('#lc_time').attr("value", "3");
		$('#dp_date').attr("value", "year");
		$('#dp_time').attr("value", "3");
		$('#td_date').attr("value", "year");
		$('#td_time').attr("value", "3");
		$("td[id^='day_']").hide();
		$("td[id^='year_']").removeClass("lxxzselected");
		// $("#year_3").addClass("lxxzselected");
		$("td[id^='week_']").hide();
		$("td[id^='month_']").hide();
		$("td[id^='hour_']").hide();
		$("td[id^='year_']").show();

		$("#rzyn td").removeClass("lxxzselected");
		$("#Year").addClass("lxxzselected");
		clearRiQiKongjian();
		showTimePicker();
		getspan('year_3');
	}
	if (type == "Hour") {
		$('#qy_date').attr("value", "hour");
		$('#qy_time').attr("value", "1");
		$('#lc_date').attr("value", "hour");
		$('#lc_time').attr("value", "1");
		$('#dp_date').attr("value", "hour");
		$('#dp_time').attr("value", "1");
		$('#td_date').attr("value", "hour");
		$('#td_time').attr("value", "1");
		$("td[id^='day_']").hide();
		$("td[id^='hour_']").removeClass("lxxzselected");
		// $("#year_3").addClass("lxxzselected");
		$("td[id^='week_']").hide();
		$("td[id^='year_']").hide();
		$("td[id^='month_']").hide();
		$("td[id^='hour_']").show();

		$("#rzyn td").removeClass("lxxzselected");
		$("#Hour").addClass("lxxzselected");
		showTimePicker();
		changeDataPicker();
		getspan('hour_1');
	}
	// if (pageType == 1) {
	// $('#qy_currentPage').attr("value", "");
	// ajaxQy(1);
	// } else if (pageType == 2) {
	// $('#lc_currentPage').attr("value", "");
	// ajaxLc(1);
	// } else if (pageType == 3) {
	// $('#dp_currentPage').attr("value", "");
	// ajaxDp(1);
	// }
}
function changeDataPicker() {
	var startDate = (new Date());
	startDate = startDate.getFullYear() + "-" + (startDate.getMonth() + 1)
			+ "-" + startDate.getDate();
	var endDate = (new Date());
	endDate = endDate.getFullYear() + "-" + (endDate.getMonth() + 1) + "-"
			+ endDate.getDate();
	var dateObj = {
		theme : 'ta', // 日期选择器TA主题
		autoCommit : false, // 自动提交，完成日期初始化，以及图表的展示拉取
		isTodayValid : true,
		startDate : startDate,
		endDate : endDate,
		needCompare : true,
		startCompareDate : '',
		endCompareDate : '',
		singleCompare : false,
		defaultText : ' 至 ',
		autoSubmit : false,
		shortOpr : true,
		target : 'datePicker',
		calendars : 2,
		isSingleDay : true,
		singleCompare : false,
		// dayRangeMax: 1,
		inputTrigger : 'input_trigger',
		compareCheckboxId : false,
		success : function(obj) {
			showLoading();
			if (pageType == 1) {
				if ($("#qy_time").val() != "")// 处于日期选择框时
		{
			$('#qy_startDate').attr("value", $('#startDate').val());
			$('#qy_endDate').attr("value", $('#endDate').val());
			getspan('hour_0');
		}
	} else if (pageType == 2) {
		if ($("#lc_time").val() != "")// 处于日期选择框时
		{
			$('#lc_startDate').attr("value", $('#startDate').val());
			$('#lc_endDate').attr("value", $('#endDate').val());
			getspan('hour_0');
		}
	} else if (pageType == 3) {
		if ($("#dp_time").val() != "")// 处于日期选择框时
		{
			$('#dp_startDate').attr("value", $('#startDate').val());
			$('#dp_endDate').attr("value", $('#endDate').val());
			getspan('hour_0');
		}
	} else if (pageType == 4) {
		if ($("#td_time").val() != "")// 处于日期选择框时
		{
			$('#td_startDate').attr("value", $('#startDate').val());
			$('#td_endDate').attr("value", $('#endDate').val());
			getspan('hour_0');
		}
	}

}
	};
	clearRiQiKongjian();
	new pickerDateRange("date", dateObj);
}
function clearRiQiKongjian() {
	$("#shijianduibi").html("");
	$("#shijianduibi")
			.html(
					"<div id=\"div_date\" class=\"nocheckoption\"><span id=\"date\"></span></div>")
}
function getspan(type) {
	$('#qy_time').attr("value", type.split("_")[1]);
	$('#lc_time').attr("value", type.split("_")[1]);
	$('#dp_time').attr("value", type.split("_")[1]);
	$('#td_time').attr("value", type.split("_")[1]);
	if (type == "day_0") {
		$("#shijianduibi").addClass("lxxzselected");
	} else {
		$("#shijianduibi").removeClass("lxxzselected");
	}
	$("#divDay table td").removeClass("lxxzselected");
	$("#" + type).addClass("lxxzselected");
	p_type = type;
	showTime(type);
	if (pageType == 1) {
		$('#qy_currentPage').attr("value", "");
		ajaxQy(1);
	} else if (pageType == 2) {
		$('#lc_currentPage').attr("value", "");
		ajaxLc(1);
	} else if (pageType == 3) {
		$('#dp_currentPage').attr("value", "");
		ajaxDp(1);
	} else if (pageType == 4) {
		$('#td_currentPage').attr("value", "");
		ajaxTd(1);
	}
}

var selectedId = new Array();
var winWidth = 0;
var numNum = 0;

// 初始化加载事件
function overLoad(id) {
	winWidth = $(window).width();
	numNum = parseInt(winWidth / 1600 * 15);
	$(".subbus").each(function() {
		var str = $.trim($(this).html());
		$(this).html(sub(str, numNum));
	});
	showTimePicker();
	// 初始化加载更换广场
	var gcId = $('#selectedGcString').val();
	// 循环已经选择的广场id默认选中
	var gcList = gcId.split(",");
	for ( var i = 0; i < gcList.length; i++) {
		selectedId.push(gcList[i]);
		// 修改样式使选中
		$('#' + gcList[i]).children().removeClass("hide");
		$('#selected' + gcList[i]).children().removeClass("hide");
	}
	$("#guojiaCombo>option").remove();
	$('#guojiaCombo').html("<option value='-1'>请选择</option>");
	var guojiaList = eval($('#guojia').val());
	for ( var i = 0; i < guojiaList.length; i++) {
		$(
				"<option value=" + guojiaList[i].siteid + ">"
						+ guojiaList[i].sitename + "</option>").appendTo(
				$('#guojiaCombo'));
	}
	// 如果没有可以选择的场所类型
	var leftSelect = $('#leftSelect').val();
	if (leftSelect == null || leftSelect == "") {
		$('#comboDiv').hide();
		$('#dateDiv').hide();
		$('#divfanye').hide();
		// $('#dataDes').html("没有数据！");
		/** 新增2015年12月7日16:03:17 * */
		$('#formTitle').remove();
		$('#formDesc').remove();
		$('#formKongbai').remove();
		$('#zhanwushuju').show();
		/** 新增2015年12月7日16:03:17 * */
		hideLoading();
		return;
	}
	showLoading();
	pageType = id;
	comboLd(id);
}

// 下拉框联动事件
function comboLd(type) {
	// 清空搜索框
	if (type == 1) {
		$('#qyInput').attr("value", "");
		$('#qy_inputName').attr("value", "");
		$('#qy_currentPage').attr("value", "");
	} else if (type == 2) {
		$('#lcInput').attr("value", "");
		$('#lc_inputName').attr("value", "");
		$('#lc_currentPage').attr("value", "");
	} else if (type == 3) {
		$('#dpInput').attr("value", "");
		$('#dp_inputName').attr("value", "");
		$('#dp_currentPage').attr("value", "");
		// 如果要默认选中区域/楼层下的店铺时
		var regionSiteId = $('#regionSiteId').val();
		var floorSiteId = $('#floorSiteId').val();
		if(regionSiteId!=undefined&&regionSiteId!=null&&regionSiteId!=""){
			// 默认选中区域
			$("#leftSelect").val("400");
		}
		else if(floorSiteId!=undefined&&floorSiteId!=null&&floorSiteId!=""){
			// 默认选中楼层
			$("#leftSelect").val("500");
		}
	} else if (type == 4) {
		$('#tdInput').attr("value", "");
		$('#td_inputName').attr("value", "");
		$('#td_currentPage').attr("value", "");
	}
	var id = $('#leftSelect').val();
	// 如果选中了广场
	if (id == 300) {
		var gcList = eval($('#rightGcList').val());
		$("#rightSelect>option").remove();
		for ( var i = 0; i < gcList.length; i++) {
			$(
					"<option value=" + gcList[i].siteid + ">"
							+ gcList[i].sitename + "</option>").appendTo(
					$('#rightSelect'));
		}
	}
	// 如果选中了区域
	else if (id == 400) {
		var qyList = eval($('#rightQyList').val());
		$("#rightSelect>option").remove();
		for ( var i = 0; i < qyList.length; i++) {
			$(
					"<option value=" + qyList[i].siteid + ">"
							+ qyList[i].sitename + "</option>").appendTo(
					$('#rightSelect'));
		}
		// 如果要默认选中区域下的店铺时2016年2月19日11:40:10
		var regionSiteId = $('#regionSiteId').val();
		if(regionSiteId!=undefined&&regionSiteId!=null&&regionSiteId!=""){
			// 默认选中楼层
			$("#rightSelect").val(regionSiteId);
			$('#regionSiteId').val("");// 销毁上次保存的默认区域
		}
	}
	// 如果选中了楼层
	else if (id == 500) {
		var lcList = eval($('#rightLcList').val());
		$("#rightSelect>option").remove();
		for ( var i = 0; i < lcList.length; i++) {
			$(
					"<option value=" + lcList[i].siteid + ">"
							+ lcList[i].sitename + "</option>").appendTo(
					$('#rightSelect'));
		}
		// 如果要默认选中楼层下的店铺时
		var floorSiteId = $('#floorSiteId').val();
		if(floorSiteId!=undefined&&floorSiteId!=null&&floorSiteId!=""){
			// 默认选中楼层
			$("#rightSelect").val(floorSiteId);
			$('#floorSiteId').val("");// 销毁上次保存的默认楼层
		}
	}
	// 如果选中了店铺
	else if (id == 600) {
		var dpList = eval($('#rightDpList').val());
		$("#rightSelect>option").remove();
		for ( var i = 0; i < dpList.length; i++) {
			$(
					"<option value=" + dpList[i].siteid + ">"
							+ dpList[i].sitename + "</option>").appendTo(
					$('#rightSelect'));
		}
	}
	changeTime('Day');
	// if (type == 1) {
	// ajaxQy(0);
	// } else if (type == 2) {
	// ajaxLc(0);
	// } else if (type == 3) {
	// ajaxDp(0);
	// }
}

// 右侧下拉框事件
function comboRight(id) {
	if (id == 1) {
		// 清空搜索框
		$('#qyInput').attr("value", "");
		$('#qy_inputName').attr("value", "");
		$('#qy_currentPage').attr("value", "");
		// ajaxQy(0);
	} else if (id == 2) {
		// 清空搜索框
		$('#lcInput').attr("value", "");
		$('#lc_inputName').attr("value", "");
		$('#lc_currentPage').attr("value", "");
		// ajaxLc(0);
	} else if (id == 3) {
		// 清空搜索框
		$('#dpInput').attr("value", "");
		$('#dp_inputName').attr("value", "");
		$('#dp_currentPage').attr("value", "");
		// ajaxDp(0);
	} else if (id == 4) {
		// 清空搜索框
		$('#tdInput').attr("value", "");
		$('#td_inputName').attr("value", "");
		$('#td_currentPage').attr("value", "");
	}
	changeTime('Day');
}

// 计算动态指标个数
function getIndexNum(indexPer){
	var i = 0;

	// 判断是否有指标权限
	var isHaveIndex = $('#isHaveIndex').val();
	// 如果没有视频指标权限
	if(isHaveIndex=="0"){
		i+=1;
	}
	if (indexPer.index0Flag == "Y"&&isHaveIndex!="0") {
		i+=1;
	}
	if (indexPer.index1Flag == "Y"&&isHaveIndex!="0") {
		i+=1;
	}
	if (indexPer.index2Flag == "Y") {
		i+=1;
	}
	if (indexPer.index3Flag == "Y") {
		i+=1;
	}
	if (indexPer.index4Flag == "Y") {
		i+=1;
	}
	if (indexPer.index5Flag == "Y") {
		i+=1;
	}
	if (indexPer.index6Flag == "Y") {
		i+=1;
	}
	if (indexPer.index7Flag == "Y") {
		i+=1;
	}
	if (indexPer.index8Flag == "Y") {
		i+=1;
	}
	if (indexPer.index9Flag == "Y") {
		i+=1;
	}
	if (indexPer.index10Flag == "Y") {
		i+=1;
	}
	if (indexPer.index11Flag == "Y") {
		i+=1;
	}
	if (indexPer.index12Flag == "Y") {
		i+=1;
	}
	if (indexPer.index13Flag == "Y") {
		i+=1;
	}
	if (indexPer.index14Flag == "Y") {
		i+=1;
	}
	if (indexPer.index15Flag == "Y") {
		i+=1;
	}
	if (indexPer.index16Flag == "Y") {
		i+=1;
	}
	if (indexPer.index17Flag == "Y") {
		i+=1;
	}
	if (indexPer.index18Flag == "Y") {
		i+=1;
	}
	if (indexPer.index19Flag == "Y") {
		i+=1;
	}
	if (indexPer.index20Flag == "Y") {
		i+=1;
	}
	if (indexPer.index21Flag == "Y") {
		i+=1;
	}
	if (indexPer.index22Flag == "Y") {
		i+=1;
	}
	if (indexPer.index23Flag == "Y"&&isHaveIndex!="0") {
		i+=1;
	}
	// 2015年12月28日10:11:40新增24、26、30、31、32
	if (indexPer.index24Flag == "Y") {
		i+=1;
	}
	if (indexPer.index25Flag == "Y") {
		i+=1;
	}
	if (indexPer.index26Flag == "Y") {
		i+=1;
	}
	if (indexPer.index27Flag == "Y") {
		i+=1;
	}
	if (indexPer.index28Flag == "Y") {
		i+=1;
	}
	if (indexPer.index29Flag == "Y") {
		i+=1;
	}
	if (indexPer.index30Flag == "Y") {
		i+=1;
	}
	if (indexPer.index31Flag == "Y") {
		i+=1;
	}
	if (indexPer.index32Flag == "Y") {
		i+=1;
	}
	if (indexPer.index33Flag == "Y") {
		i+=1;
	}
	if (indexPer.index34Flag == "Y") {
		i+=1;
	}
	if (indexPer.index35Flag == "Y") {
		i+=1;
	}
	if (indexPer.index36Flag == "Y") {
		i+=1;
	}
	if (indexPer.index37Flag == "Y") {
		i+=1;
	}
	if (indexPer.index38Flag == "Y") {
		i+=1;
	}
	if (indexPer.index39Flag == "Y") {
		i+=1;
	}
	if (indexPer.index40Flag == "Y") {
		i+=1;
	}
	if (indexPer.index41Flag == "Y") {
		i+=1;
	}
	if (indexPer.index42Flag == "Y") {
		i+=1;
	}
	if (indexPer.index43Flag == "Y") {
		i+=1;
	}
	if (indexPer.index44Flag == "Y") {
		i+=1;
	}
	if (indexPer.index45Flag == "Y") {
		i+=1;
	}
	if (indexPer.index46Flag == "Y") {
		i+=1;
	}
	return i;
}

// 拼接指标头
function getTableTitle(indexPer) {
	// alert($('#formTitle').css("width"));
	// 生成指标名称（数据说明模块），2015年12月11日18:43:48
	var noteTitle;
	if (pageType == 1) {
		noteTitle = "区域";
	} else if (pageType == 2) {
		noteTitle = "楼层";
	} else if (pageType == 3) {
		noteTitle = "店铺";
	} else if (pageType == 4) {
		noteTitle = "通道";
	}
	var zhibiaomingcheng = "";
// var qian = "<tr><th class='xykongbai'></th><th class='xyxuhao'>编号</th><th
// class='gailanmingcheng'>"+noteTitle+"名称</th>";
// var hou = "<th class='xykongbai'></th></tr>";
	var indexNum = getIndexNum(indexPer);
	var bhWidth = 30;
	var mcWidth = 300;
	var xqWidth = 70;
	var indexWidth = 150;
	var minWidth = 400+parseInt(indexNum)*150;
	var llqWidth = $('#formTitle').css("width");
	llqWidth = llqWidth.substring(0,llqWidth.length-2);
	// 如果浏览器过宽或者指标过少，将多余宽度平均分配到指标列中
	if(parseInt(llqWidth)>minWidth+ 220){
		var duoWidth = parseInt(llqWidth) - minWidth - 220;
		var ygWidth = duoWidth/parseInt(indexNum);
// bhWidth+=ygWidth+ygWidth;
// mcWidth+=ygWidth+ygWidth;
// xqWidth+=ygWidth;
		indexWidth+=ygWidth;
	}
	var qian = "<tr><th width="+bhWidth+">编号</th><th width="+mcWidth+">"+noteTitle+"名称</th><th width="+xqWidth+">详情</th>";
	var hou = "</tr>";
	var center = "";
	// 判断是否有指标权限，2016年2月17日17:10:42
	var isHaveIndex = $('#isHaveIndex').val();
	if(isHaveIndex=="0"&&indexPer.index0Flag == "Y"){
		if(pageType == 1){
			center += "<th width="+indexWidth+">区域客流（人次）</th>";
			zhibiaomingcheng += "区域客流（人次）&";
		}
		else if(pageType == 2){
			center += "<th width="+indexWidth+">楼层客流（人次）</th>";
			zhibiaomingcheng += "楼层客流（人次）&";
		}
	}
	if (indexPer.index0Flag == "Y"&&isHaveIndex!="0") {
		center += "<th width="+indexWidth+">客流量（人次）</th>";
		zhibiaomingcheng += "客流量（人次）&";
	}
	if (indexPer.index1Flag == "Y"&&isHaveIndex!="0") {
		center += "<th width="+indexWidth+">集客力（人/m²）</th>";
		zhibiaomingcheng += "集客力（人/m²）&";
	}
	if (indexPer.index2Flag == "Y") {
		center += "<th width="+indexWidth+">人效（元/人）</th>";
		zhibiaomingcheng += "人效（元/人）&";
	}
	if (indexPer.index3Flag == "Y") {
		center += "<th width="+indexWidth+">销售额（元）</th>";
		zhibiaomingcheng += "销售额（元）&";
	}
	if (indexPer.index4Flag == "Y") {
		center += "<th width="+indexWidth+">提袋率（%）</th>";
		zhibiaomingcheng += "提袋率（%）&";
	}
	if (indexPer.index5Flag == "Y") {
		center += "<th width="+indexWidth+">客单价（元/人次）</th>";
		zhibiaomingcheng += "客单价（元/人次）&";
	}
	if (indexPer.index6Flag == "Y") {
		center += "<th width="+indexWidth+">坪效（元/m²）</th>";
		zhibiaomingcheng += "坪效（元/m²）&";
	}
	if (indexPer.index7Flag == "Y") {
		center += "<th width="+indexWidth+">顾客数（人）</th>";
		zhibiaomingcheng += "顾客数（人）&";
	}
	if (indexPer.index8Flag == "Y") {
		center += "<th width="+indexWidth+">平均游逛时间（分）</th>";
		zhibiaomingcheng += "平均游逛时间（分）&";
	}
	if (indexPer.index9Flag == "Y") {
		center += "<th width="+indexWidth+">新顾客数（人）</th>";
		zhibiaomingcheng += "新顾客数（人）&";
	}
	if (indexPer.index10Flag == "Y") {
		center += "<th width="+indexWidth+">老顾客数（人）</th>";
		zhibiaomingcheng += "老顾客数（人）&";
	}
	if (indexPer.index11Flag == "Y") {
		center += "<th width="+indexWidth+">新顾客占比（%）</th>";
		zhibiaomingcheng += "新顾客占比（%）&";
	}
	if (indexPer.index12Flag == "Y") {
		center += "<th width="+indexWidth+">老顾客占比（%）</th>";
		zhibiaomingcheng += "老顾客占比（%）&";
	}
	if (indexPer.index13Flag == "Y") {
		center += "<th width="+indexWidth+">进店率（%）</th>";
		zhibiaomingcheng += "进店率（%）&";
	}
	if (indexPer.index14Flag == "Y") {
		center += "<th width="+indexWidth+">返店率（%）</th>";
		zhibiaomingcheng += "返店率（%）&";
	}
	if (indexPer.index15Flag == "Y") {
		center += "<th width="+indexWidth+">流失量</th>";
		zhibiaomingcheng += "流失量&";
	}
	if (indexPer.index16Flag == "Y") {
		center += "<th width="+indexWidth+">流失率</th>";
		zhibiaomingcheng += "流失率&";
	}
	if (indexPer.index17Flag == "Y") {
		center += "<th width="+indexWidth+">回流量</th>";
		zhibiaomingcheng += "回流量&";
	}
	if (indexPer.index18Flag == "Y") {
		center += "<th width="+indexWidth+">回流率</th>";
		zhibiaomingcheng += "回流率&";
	}
	if (indexPer.index19Flag == "Y") {
		center += "<th width="+indexWidth+">到访会员人数（人）</th>";
		zhibiaomingcheng += "到访会员人数（人）&";
	}
	if (indexPer.index20Flag == "Y") {
		center += "<th width="+indexWidth+">会员人数占比（%）</th>";
		zhibiaomingcheng += "会员人数占比（%）&";
	}
	if (indexPer.index21Flag == "Y") {
		center += "<th width="+indexWidth+">平均滞留时间（min）</th>";
		zhibiaomingcheng += "平均滞留时间（min）&";
	}
	if (indexPer.index22Flag == "Y") {
		center += "<th width="+indexWidth+">滞留量（人次）</th>";
		zhibiaomingcheng += "滞留量（人次）&";
	}
	if (indexPer.index23Flag == "Y"&&isHaveIndex!="0") {
		center += "<th width="+indexWidth+">出客流量（人次）</th>";
		zhibiaomingcheng += "出客流量（人次）&";
	}
	// 2015年12月28日10:11:40新增24、26、30、31、32
	if (indexPer.index24Flag == "Y") {
		center += "<th width="+indexWidth+">活跃用户数（人）</th>";
		zhibiaomingcheng += "活跃用户数（人）&";
	}
	if (indexPer.index25Flag == "Y") {
		center += "<th width="+indexWidth+">活跃率（%）</th>";
		zhibiaomingcheng += "活跃率（%）&";
	}
	if (indexPer.index26Flag == "Y") {
		center += "<th width="+indexWidth+">沉默用户数（人）</th>";
		zhibiaomingcheng += "沉默用户数（人）&";
	}
	if (indexPer.index27Flag == "Y") {
		center += "<th width="+indexWidth+">沉默率（%）</th>";
		zhibiaomingcheng += "沉默率（%）&";
	}
	if (indexPer.index28Flag == "Y") {
		center += "<th width="+indexWidth+">存留量（人）</th>";
		zhibiaomingcheng += "存留量（人）&";
	}
	if (indexPer.index29Flag == "Y") {
		center += "<th width="+indexWidth+">存留率（%）</th>";
		zhibiaomingcheng += "存留率（%）&";
	}
	if (indexPer.index30Flag == "Y") {
		center += "<th width="+indexWidth+">上网人数（人）</th>";
		zhibiaomingcheng += "上网人数（人）&";
	}
	if (indexPer.index31Flag == "Y") {
		center += "<th width="+indexWidth+">新上网人数（人）</th>";
		zhibiaomingcheng += "新上网人数（人）&";
	}
	if (indexPer.index32Flag == "Y") {
		center += "<th width="+indexWidth+">上网平均时长（min）</th>";
		zhibiaomingcheng += "上网平均时长（min）&";
	}
	if (indexPer.index33Flag == "Y") {
		center += "<th width="+indexWidth+">上网平均次数（次）</th>";
		zhibiaomingcheng += "上网平均次数（次）&";
	}
	if (indexPer.index34Flag == "Y") {
		center += "<th width="+indexWidth+">上网人数占比（%）</th>";
		zhibiaomingcheng += "上网人数占比（%）&";
	}
	if (indexPer.index35Flag == "Y") {
		center += "<th width="+indexWidth+">连接用户数（人）</th>";
		zhibiaomingcheng += "连接用户数（人）&";
	}
	if (indexPer.index36Flag == "Y") {
		center += "<th width="+indexWidth+">新增连接用户数（人）</th>";
		zhibiaomingcheng += "新增连接用户数（人）&";
	}
	if (indexPer.index37Flag == "Y") {
		center += "<th width="+indexWidth+">首次到店人数（人）</th>";
		zhibiaomingcheng += "首次到店人数（人）&";
	}
	if (indexPer.index38Flag == "Y") {
		center += "<th width="+indexWidth+">首次到店率（%）</th>";
		zhibiaomingcheng += "首次到店率（%）&";
	}
	if (indexPer.index39Flag == "Y") {
		center += "<th width="+indexWidth+">wifi开启率（%）</th>";
		zhibiaomingcheng += "wifi开启率（%）&";
	}
	if (indexPer.index40Flag == "Y") {
		center += "<th width="+indexWidth+">历史用户数（人）</th>";
		zhibiaomingcheng += "历史用户数（人）&";
	}
	if (indexPer.index41Flag == "Y") {
		center += "<th width="+indexWidth+">客流人次（人次）</th>";
		zhibiaomingcheng += "客流人次（人次）&";
	}
	if (indexPer.index42Flag == "Y") {
		center += "<th width="+indexWidth+">游逛深度</th>";
		zhibiaomingcheng += "游逛深度&";
	}
	if (indexPer.index43Flag == "Y") {
		center += "<th width="+indexWidth+">会员总数（人）</th>";
		zhibiaomingcheng += "会员总数（人）&";
	}
	if (indexPer.index44Flag == "Y") {
		center += "<th width="+indexWidth+">服务能力（人次/人）</th>";
		zhibiaomingcheng += "服务能力（人次/人）&";
	}
	if (indexPer.index45Flag == "Y") {
		center += "<th width="+indexWidth+">交易笔数（笔）</th>";
		zhibiaomingcheng += "交易笔数（笔）&";
	}
	if (indexPer.index46Flag == "Y") {
		center += "<th width="+indexWidth+">平均活跃天数（天）</th>";
		zhibiaomingcheng += "平均活跃天数（天）&";
	}
	if (zhibiaomingcheng != "") {
		zhibiaomingcheng = zhibiaomingcheng.substring(0,
				zhibiaomingcheng.length - 1);
		$('#zhibiaomingcheng').append("指标名称：" + zhibiaomingcheng);
	}
	return qian + center + hou;
}

// 获取动态指标内容
function getActiveIndex(indexList,indexPer){
	var tbody = "";
	for ( var i = 1; i < indexList.length + 1; i++) {
		var lieList = "";
		// 判断是否有指标权限，2016年2月17日17:10:42
		var isHaveIndex = $('#isHaveIndex').val();
		if(isHaveIndex=="0"&&indexPer.index0Flag == "Y"){
			if (pageType == 1) {
				lieList += "<td style='text-align:right'>" + indexList[i - 1].index0_0
				+ "</td>";
			}
			else if (pageType == 2) {
				lieList += "<td style='text-align:right'>" + indexList[i - 1].index0_1
				+ "</td>";
			}
		}
		if (indexPer.index0Flag == "Y"&&isHaveIndex!="0") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index0
					+ "</td>";
		}
		if (indexPer.index1Flag == "Y"&&isHaveIndex!="0") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index1
					+ "</td>";
		}
		if (indexPer.index2Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index2
					+ "</td>";
		}
		if (indexPer.index3Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index3
					+ "</td>";
		}
		if (indexPer.index4Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index4
					+ "</td>";
		}
		if (indexPer.index5Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index5
					+ "</td>";
		}
		if (indexPer.index6Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index6
					+ "</td>";
		}
		if (indexPer.index7Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index7
					+ "</td>";
		}
		if (indexPer.index8Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index8
					+ "</td>";
		}
		if (indexPer.index9Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index9
					+ "</td>";
		}
		if (indexPer.index10Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index10
					+ "</td>";
		}
		if (indexPer.index11Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index11
					+ "</td>";
		}
		if (indexPer.index12Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index12
					+ "</td>";
		}
		if (indexPer.index13Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index13
					+ "</td>";
		}
		if (indexPer.index14Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index14
					+ "</td>";
		}
		if (indexPer.index15Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index15
					+ "</td>";
		}
		if (indexPer.index16Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index16
					+ "</td>";
		}
		if (indexPer.index17Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index17
					+ "</td>";
		}
		if (indexPer.index18Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index18
					+ "</td>";
		}
		if (indexPer.index19Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index19
					+ "</td>";
		}
		if (indexPer.index20Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index20
					+ "</td>";
		}
		if (indexPer.index21Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index21
					+ "</td>";
		}
		if (indexPer.index22Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index22
					+ "</td>";
		}
		if (indexPer.index23Flag == "Y"&&isHaveIndex!="0") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index23
					+ "</td>";
		}
		// 2015年12月28日10:19:48新增龙湖wifi指标
		if (indexPer.index24Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index24
					+ "</td>";
		}
		if (indexPer.index25Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index25
					+ "</td>";
		}
		if (indexPer.index26Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index26
					+ "</td>";
		}
		if (indexPer.index27Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index27
					+ "</td>";
		}
		if (indexPer.index28Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index28
					+ "</td>";
		}
		if (indexPer.index29Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index29
					+ "</td>";
		}
		if (indexPer.index30Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index30
					+ "</td>";
		}
		if (indexPer.index31Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index31
					+ "</td>";
		}
		if (indexPer.index32Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index32
					+ "</td>";
		}
		if (indexPer.index33Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index33
					+ "</td>";
		}
		if (indexPer.index34Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index34
					+ "</td>";
		}
		if (indexPer.index35Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index35
					+ "</td>";
		}
		if (indexPer.index36Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index36
					+ "</td>";
		}
		if (indexPer.index37Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index37
					+ "</td>";
		}
		if (indexPer.index38Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index38
					+ "</td>";
		}
		if (indexPer.index39Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index39
					+ "</td>";
		}
		if (indexPer.index40Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index40
					+ "</td>";
		}
		if (indexPer.index41Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index41
					+ "</td>";
		}
		if (indexPer.index42Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index42
					+ "</td>";
		}
		if (indexPer.index43Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index43
					+ "</td>";
		}
		if (indexPer.index44Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index44
					+ "</td>";
		}
		if (indexPer.index45Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index45
					+ "</td>";
		}
		if (indexPer.index46Flag == "Y") {
			lieList += "<td style='text-align:right'>" + indexList[i - 1].index46
					+ "</td>";
		}
// var xuhao = i+(msgs.currentPage-1)*12;
		var xuhao = i;
// $('#myTable')
// .append(
// "<tr><td class='xytd'></td><td class='xyxuhao'>"
// + xuhao
// + "</td><td class='gailanmingcheng'><span>"
// + indexList[i - 1].siteName
// + "</span><span class='floatright hand'><a onclick='openQyDetail(&quot;"
// + indexList[i - 1].siteId
// + "&quot;)' class='orange'>详情>></a></span></td>"
// + lieList + "<td></td></tr>");
		if (pageType == 1) {
			tbody+="<tr><td style='text-align:center'>"
				+ xuhao
				+ "</td><td style='text-align:center'>"
				+ indexList[i - 1].siteName
				+ "</td><td style='text-align:center'><span class='hand'><a onclick='openQyDetail(&quot;"
				+ indexList[i - 1].siteId
				+ "&quot;)' class='orange'>详情</a></span></td>"
				+ lieList + "</tr>";
		} else if (pageType == 2) {
			tbody+="<tr><td style='text-align:center'>"
				+ xuhao
				+ "</td><td style='text-align:center'>"
				+ indexList[i - 1].siteName
				+ "</td><td style='text-align:center'><span class='hand'><a onclick='openLcDetail(&quot;"
				+ indexList[i - 1].siteId
				+ "&quot;)' class='orange'>详情</a></span></td>"
				+ lieList + "</tr>";
		} else if (pageType == 3) {
			tbody+="<tr><td style='text-align:center'>"
				+ xuhao
				+ "</td><td style='text-align:center'>"
				+ indexList[i - 1].siteName
				+ "</td><td style='text-align:center'><span class='hand'><a onclick='openDpDetail(&quot;"
				+ indexList[i - 1].siteId
				+ "&quot;)' class='orange'>详情</a></span></td>"
				+ lieList + "</tr>";
		} else if (pageType == 4) {
			tbody+="<tr><td >"
				+ xuhao
				+ "</td><td style='text-align:center'>"
				+ indexList[i - 1].siteName
				+ "</td><td style='text-align:center'><span class='hand'><a onclick='openTdDetail(&quot;"
				+ indexList[i - 1].siteId
				+ "&quot;)' class='orange'>详情</a></span></td>"
				+ lieList + "</tr>";
		}
	}
	return tbody;
}

// ajax查询区域以及指标(0:需要初始化到日、当天)
function ajaxQy(id) {
	if (id == 0) {
		// 初始化到日
		changeTime('Day');
		// 初始化到当天
		getspan('day_1');
		// 初始化默认是日
		$('#qy_date').attr("value", "day");
		// 初始化默认是当天
		$('#qy_time').attr("value", "1");
	}
	// 场所类型
	var siteType = $('#leftSelect').val();
	// 场所id
	var siteId = $('#rightSelect').val();
	// 如果场所类型为空，不作处理
	if (siteType == null || siteType == "") {
		hideLoading();
		return;
	}
	// 查询栏中区域名称
	var qyName = $('#qy_inputName').val();
	if (qyName != undefined && qyName != null && qyName != "") {
		qyName = qyName.trim();
	}
	// 日周月年
	var qyDate = $('#qy_date').val();
	// 当天、7、14、30
	var qyTime = $('#qy_time').val();
	// 开始日期
	var startDate = $('#qy_startDate').val();
	// 结束日期
	var endDate = $('#qy_endDate').val();
	// 当前页
	var currentPage = $('#qy_currentPage').val();
	$
			.ajax( {
				type : "GET",
				contentType : "application/json",
				data : {
					siteType : siteType,
					siteId : siteId,
					qyName : encodeURI(qyName),
					qyDate : qyDate,
					qyTime : qyTime,
					startDate : startDate,
					endDate : endDate,
					currentPage : currentPage
				},
				dataType : 'json',
				url : "getQyView",
				async : true,
				success : function(msgs) {
// $('#leftFY').show();
// $('#rightFY').show();
					// 动态获取指标,2015年12月8日14:18:20
				// $('#myTable tr:not(:first)').empty();
				var indexPer = msgs.index;
// $('#myTable').empty();
				var tableTitle = getTableTitle(indexPer);
// $('#myTable').append(tableTitle);
				// 动态获取指标,2015年12月8日14:18:20
				var indexList = msgs.indexList;
// $('#curpage').html(msgs.currentPage);
// $('#allpage').html(msgs.maxPage);
// if (msgs.maxPage == 1) {
// $('#leftFY').hide();
// $('#rightFY').hide();
// }
// if (msgs.currentPage == 1) {
// $('#leftFY').hide();
// }
// if (msgs.currentPage == msgs.maxPage) {
// $('#rightFY').hide();
// }
				if (indexList.length == 0) {
// $('#myTable')
// .append(
// "<tr><td class='xytd textcenter' colspan=8>没有您要查询的数据！<td></td></tr>");
					$("#hdtable").val("");
					showNewTable("<table id='tabledata'><thead>"+tableTitle+"</thead></table>");
				} else {
					var tbody = getActiveIndex(indexList,indexPer);
					var resultTable = "<table class='row-border stripe' id='tabledata'><thead>"+tableTitle+"</thead><tbody>"+tbody+"</tbody></table>";
					showNewTable(resultTable);
					$("#hdtable").val(resultTable);
				}
				hideLoading();
			},
			error : function(mm, a, b, c, d, e) {
				hideLoading();
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
			});
}

// ajax查询楼层以及指标(0:需要初始化到日、当天)
function ajaxLc(id) {
	if (id == 0) {
		// 初始化到日
		changeTime('Day');
		// 初始化到当天
		getspan('day_1');
		// 初始化默认是日
		$('#lc_date').attr("value", "day");
		// 初始化默认是当天
		$('#lc_time').attr("value", "1");
	}
	// 场所类型
	var siteType = $('#leftSelect').val();
	// 场所id
	var siteId = $('#rightSelect').val();
	// 如果场所类型为空，不作处理
	if (siteType == null || siteType == "") {
		hideLoading();
		return;
	}
	// 查询栏中区域名称
	var lcName = $('#lc_inputName').val();
	if (lcName != undefined && lcName != null && lcName != "") {
		lcName = lcName.trim();
	}
	// 日周月年
	var lcDate = $('#lc_date').val();
	// 当天、7、14、30
	var lcTime = $('#lc_time').val();
	// 开始日期
	var startDate = $('#lc_startDate').val();
	// 结束日期
	var endDate = $('#lc_endDate').val();
	// 当前页
	var currentPage = $('#lc_currentPage').val();
	$
			.ajax( {
				type : "GET",
				contentType : "application/json",
				data : {
					siteType : siteType,
					siteId : siteId,
					lcName : encodeURI(lcName),
					lcDate : lcDate,
					lcTime : lcTime,
					startDate : startDate,
					endDate : endDate,
					currentPage : currentPage
				},
				dataType : 'json',
				url : "getLcView",
				async : true,
				success : function(msgs) {
// $('#leftFY').show();
// $('#rightFY').show();
					// 动态获取指标,2015年12月8日14:18:20
				// $('#myTable tr:not(:first)').empty();
				var indexPer = msgs.index;
// $('#myTable').empty();
				var tableTitle = getTableTitle(indexPer);
// $('#myTable').append(tableTitle);
				// 动态获取指标,2015年12月8日14:18:20
				var indexList = msgs.indexList;
// $('#curpage').html(msgs.currentPage);
// $('#allpage').html(msgs.maxPage);
// if (msgs.maxPage == 1) {
// $('#leftFY').hide();
// $('#rightFY').hide();
// }
// if (msgs.currentPage == 1) {
// $('#leftFY').hide();
// }
// if (msgs.currentPage == msgs.maxPage) {
// $('#rightFY').hide();
// }
				// var indexPer = eval($('#index').val());
				if (indexList.length == 0) {
// $('#myTable')
// .append(
// "<tr><td class='xytd textcenter' colspan=10>没有您要查询的数据！<td></td></tr>");
					showNewTable("<table id='tabledata'><thead>"+tableTitle+"</thead></table>");
					$("#hdtable").val("");
				} else {
					var tbody = getActiveIndex(indexList,indexPer);
					var resultTable = "<table class='row-border stripe' id='tabledata'><thead>"+tableTitle+"</thead><tbody>"+tbody+"</tbody></table>";
					showNewTable(resultTable);
					$("#hdtable").val(resultTable);
				}
				hideLoading();
			},
			error : function(mm, a, b, c, d, e) {
				hideLoading();
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
			});
}

// ajax查询店铺以及指标(0:需要初始化到日、当天)
function ajaxDp(id) {
	if (id == 0) {
		// 初始化到日
		changeTime('Day');
		// 初始化到当天
		getspan('day_1');
		// 初始化默认是日
		$('#dp_date').attr("value", "day");
		// 初始化默认是当天
		$('#dp_time').attr("value", "1");
	}
	// 场所类型
	var siteType = $('#leftSelect').val();
	// 场所id
	var siteId = $('#rightSelect').val();
	// 如果场所类型为空，不作处理
	if (siteType == null || siteType == "") {
		hideLoading();
		return;
	}
	// 查询栏中区域名称
	var dpName = $('#dp_inputName').val();
	if (dpName != undefined && dpName != null && dpName != "") {
		dpName = dpName.trim();
	}
	// 日周月年
	var dpDate = $('#dp_date').val();
	// 当天、7、14、30
	var dpTime = $('#dp_time').val();
	// 开始日期
	var startDate = $('#dp_startDate').val();
	// 结束日期
	var endDate = $('#dp_endDate').val();
	// 当前页
	var currentPage = $('#dp_currentPage').val();
	$
			.ajax( {
				type : "GET",
				contentType : "application/json",
				data : {
					siteType : siteType,
					siteId : siteId,
					dpName : encodeURI(dpName),
					dpDate : dpDate,
					dpTime : dpTime,
					startDate : startDate,
					endDate : endDate,
					currentPage : currentPage
				},
				dataType : 'json',
				url : "getDpView",
				async : true,
				success : function(msgs) {
// $('#leftFY').show();
// $('#rightFY').show();
					// 动态获取指标,2015年12月8日14:18:20
				// $('#myTable tr:not(:first)').empty();
				var indexPer = msgs.index;
// $('#myTable').empty();
				var tableTitle = getTableTitle(indexPer);
// $('#myTable').append(tableTitle);
				// 动态获取指标,2015年12月8日14:18:20
				var indexList = msgs.indexList;
// $('#curpage').html(msgs.currentPage);
// $('#allpage').html(msgs.maxPage);
// if (msgs.maxPage == 1) {
// $('#leftFY').hide();
// $('#rightFY').hide();
// }
// if (msgs.currentPage == 1) {
// $('#leftFY').hide();
// }
// if (msgs.currentPage == msgs.maxPage) {
// $('#rightFY').hide();
// }
				// var indexPer = eval($('#index').val());
				if (indexList.length == 0) {
// $('#myTable')
// .append(
// "<tr><td class='xytd textcenter' colspan=12>没有您要查询的数据！<td></td></tr>");
					showNewTable("<table id='tabledata'><thead>"+tableTitle+"</thead></table>");
					$("#hdtable").val("");
				} else {
					var tbody = getActiveIndex(indexList,indexPer);
					var resultTable = "<table class='row-border stripe' id='tabledata'><thead>"+tableTitle+"</thead><tbody>"+tbody+"</tbody></table>";
					showNewTable(resultTable);
					$("#hdtable").val(resultTable);
				}
				hideLoading();
			},
			error : function(mm, a, b, c, d, e) {
				hideLoading();
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
			});
}

// ajax查询通道以及指标(0:需要初始化到日、当天)
function ajaxTd(id) {
	if (id == 0) {
		// 初始化到日
		changeTime('Day');
		// 初始化到当天
		getspan('day_1');
		// 初始化默认是日
		$('#td_date').attr("value", "day");
		// 初始化默认是当天
		$('#td_time').attr("value", "1");
	}
	// 场所类型
	var siteType = $('#leftSelect').val();
	// 场所id
	var siteId = $('#rightSelect').val();
	// 如果场所类型为空，不作处理
	if (siteType == null || siteType == "") {
		hideLoading();
		return;
	}
	// 查询栏中区域名称
	var tdName = $('#td_inputName').val();
	if (tdName != undefined && tdName != null && tdName != "") {
		tdName = tdName.trim();
	}
	// 日周月年
	var tdDate = $('#td_date').val();
	// 当天、7、14、30
	var tdTime = $('#td_time').val();
	// 开始日期
	var startDate = $('#td_startDate').val();
	// 结束日期
	var endDate = $('#td_endDate').val();
	// 当前页
	var currentPage = $('#td_currentPage').val();
	$
			.ajax( {
				type : "GET",
				contentType : "application/json",
				data : {
					siteType : siteType,
					siteId : siteId,
					tdName : encodeURI(tdName),
					tdDate : tdDate,
					tdTime : tdTime,
					startDate : startDate,
					endDate : endDate,
					currentPage : currentPage
				},
				dataType : 'json',
				url : "getTdView",
				async : true,
				success : function(msgs) {
// $('#leftFY').show();
// $('#rightFY').show();
					// 动态获取指标,2015年12月8日14:18:20
				// $('#myTable tr:not(:first)').empty();
				var indexPer = msgs.index;
// $('#myTable').empty();
				var tableTitle = getTableTitle(indexPer);
// $('#myTable').append(tableTitle);
				// 动态获取指标,2015年12月8日14:18:20
				var indexList = msgs.indexList;
// $('#curpage').html(msgs.currentPage);
// $('#allpage').html(msgs.maxPage);
// if (msgs.maxPage == 1) {
// $('#leftFY').hide();
// $('#rightFY').hide();
// }
// if (msgs.currentPage == 1) {
// $('#leftFY').hide();
// }
// if (msgs.currentPage == msgs.maxPage) {
// $('#rightFY').hide();
// }
				// var indexPer = eval($('#index').val());
				if (indexList.length == 0) {
// $('#myTable')
// .append(
// "<tr><td class='xytd textcenter' colspan=10>没有您要查询的数据！<td></td></tr>");
					showNewTable("<table id='tabledata'><thead>"+tableTitle+"</thead></table>");
					$("#hdtable").val("");
				} else {
					var tbody = getActiveIndex(indexList,indexPer);
					var resultTable = "<table class='row-border stripe' id='tabledata'><thead>"+tableTitle+"</thead><tbody>"+tbody+"</tbody></table>";
					showNewTable(resultTable);
					$("#hdtable").val(resultTable);
				}
				hideLoading();
			},
			error : function(mm, a, b, c, d, e) {
				hideLoading();
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
			});
}

// 打开区域详情
function openQyDetail(id) {
	var isHaveIndex = $('#isHaveIndex').val();
	var isHaveWifi = $('#isHaveWifi').val();
	if(isHaveIndex=="0"&&isHaveWifi=="1"){
		// 判断该区域下是否有店铺可以查看
		$.ajax( {
			type : "GET",
			contentType : "application/json",
			data : {
				qySiteId : id
			},
			dataType : 'json',
			url : "isQyHaveDp",
			async : true,
			success : function(msgs) {
				if(msgs.isHaveDp=="0"){
					alert("无详情数据！");
					return;
				}else{
					var gcSiteId = $('#selectedGcString').val();
					window.open('shopView?regionSiteId=' + id+"&siteId="+gcSiteId);
				}
			},
			error : function(mm, a, b, c, d, e) {
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
		});
	}
	else{
		window.open('footfallArea?siteId=' + id);
	}
}

// 打开楼层详情
function openLcDetail(id) {
	var isHaveIndex = $('#isHaveIndex').val();
	var isHaveWifi = $('#isHaveWifi').val();
	if(isHaveIndex=="0"&&isHaveWifi=="1"){
		// 判断该楼层下是否有店铺可以查看
		$.ajax( {
			type : "GET",
			contentType : "application/json",
			data : {
				lcSiteId : id
			},
			dataType : 'json',
			url : "isLcHaveDp",
			async : true,
			success : function(msgs) {
				if(msgs.isHaveDp=="0"){
					alert("无详情数据！");
					return;
				}else{
					var gcSiteId = $('#selectedGcString').val();
					window.open('shopView?floorSiteId=' + id+"&siteId="+gcSiteId);
				}
			},
			error : function(mm, a, b, c, d, e) {
				alert("服务器好像开小差了，刷新一下试试吧！");
			}
		});
	}
	else{
		window.open('footfallFloor?siteId=' + id);
	}
}

// 打开楼层详情
function openDpDetail(id) {
	window.open('footfallStore?siteId=' + id);
}

// 打开通道详情
function openTdDetail(id) {
	window.open('footfallChannel?siteId=' + id);
}

// 点击查询区域
function qySearch() {
	showTime(p_type);
	var qyInput = $('#qyInput').val().trim();
	$('#qy_inputName').attr("value", qyInput);
	ajaxQy(1);
}

// 点击查询楼层
function lcSearch() {
	showTime(p_type);
	var lcInput = $('#lcInput').val().trim();
	$('#lc_inputName').attr("value", lcInput);
	ajaxLc(1);
}

// 点击查询店铺
function dpSearch() {
	showTime(p_type);
	var dpInput = $('#dpInput').val().trim();
	$('#dp_inputName').attr("value", dpInput);
	ajaxDp(1);
}

// 点击查询通道
function tdSearch() {
	showTime(p_type);
	var tdInput = $('#tdInput').val().trim();
	$('#td_inputName').attr("value", tdInput);
	ajaxTd(1);
}

// 分页栏
function gotopage(i) {
	showTime(p_type);
	showLoading();
	// 纯数字正则
	var numRule = /(^\d*$)|(^\S+\s+\S+$)/;
	var j = 1;
	var maxPage = parseInt($("#allpage").html());
	// 首页
	if (i == 0) {
		j = 1;
	}
	// 下一页
	else if (i == 1) {
		j = parseInt($("#curpage").html()) + 1;
	}
	// 上一页
	else if (i == 2) {
		j = parseInt($("#curpage").html()) - 1;
	}
	// 跳转
	else if (i == 3) {
		var gotoPage = $("#txtpages").val().trim();
		if (gotoPage == "") {
			j = 1;
		} else if (!gotoPage.match(numRule)) {
			j == 1
		} else {
			j = parseInt(gotoPage);
		}
	}
	// 尾页
	else if (i == -1) {
		j = maxPage;
	}
	if (j < 1) {
		j = 1;
	}
	if (j > maxPage) {
		j = maxPage;
	}
	if (pageType == 1) {
		$("#qy_currentPage").val(j);
		ajaxQy(1);
	} else if (pageType == 2) {
		$("#lc_currentPage").val(j);
		ajaxLc(1);
	} else if (pageType == 3) {
		$("#dp_currentPage").val(j);
		ajaxDp(1);
	} else if (pageType == 4) {
		$("#td_currentPage").val(j);
		ajaxTd(1);
	}
}

// 计算时间
function showTime(a) {
	var sDate;
	var eDate;
	var siteTitle = $('#selectedGcNameString').val();
	var rightSelectedSiteName = $("#rightSelect").find("option:selected").text();
	var noteTitle=rightSelectedSiteName+"-";
	if (pageType == 1) {
		noteTitle += "区域";
	} else if (pageType == 2) {
		noteTitle += "楼层";
	} else if (pageType == 3) {
		noteTitle += "店铺";
	} else if (pageType == 4) {
		noteTitle += "通道";
	}
	var dateType;// 时间类型：时、日、周、月、年
	// 如果选择了时段客流
	if (a.split("_")[0] == "hour") {
		dateType = "时";
		var hourType = a.split("_")[1];
		// 如果是自己选时间
		if (hourType == "0") {
			sDate = $('#startDate').val();
			eDate = sDate;
		}
		// 如果选择了今天
		else if (hourType == "1") {
			var date = new Date();
			var year = date.getFullYear();// 年
			var month = date.getMonth() + 1;// 月
			var day = date.getDate();// 日
			sDate = year + "-" + month + "-" + day;
			eDate = sDate;
		}
		// 如果选择了昨天
		else if (hourType == "2") {
			var dd = new Date();
			dd.setDate(dd.getDate() - 1);
			var dd_year = dd.getFullYear();// 年
			var dd_month = dd.getMonth() + 1;// 月
			var dd_day = dd.getDate();// 日
			sDate = dd_year + "-" + dd_month + "-" + dd_day;
			eDate = sDate;
		}
		// $('#dataDes').html(sDate + siteTitle + noteTitle);
	}
	// 否则
	else {
		// 如果是自己选择日期
		if (a == "day_0") {
			var timeType = $("td.lxxzselected")[0].id;// 日周月年
			var startDate = $('#startDate').val();// 开始日期
			var endDate = $('#endDate').val();// 结束日期
			if (timeType == "Day") {
				dateType = "日";
				sDate = startDate;
				eDate = endDate;
			} else if (timeType == "Week") {
				dateType = "周";
				var oldDate = new Date(startDate);
				oldDate.setDate(oldDate.getDate() - oldDate.getDay() + 1);
				var oldMonth = oldDate.getMonth() + 1;
				sDate = oldDate.getFullYear() + "-" + oldMonth + "-"
						+ oldDate.getDate();
				var newDate = new Date(endDate);
				newDate.setDate(newDate.getDate() - newDate.getDay() + 7);
				var newMonth = newDate.getMonth() + 1;
				eDate = newDate.getFullYear() + "-" + newMonth + "-"
						+ newDate.getDate();

			} else if (timeType == "Month") {
				dateType = "月";
				sDate = startDate.substring(0, 7);
				eDate = endDate.substring(0, 7);
			} else if (timeType == "Year") {
				dateType = "年";
				sDate = startDate.substring(0, 4);
				eDate = endDate.substring(0, 4);
			}
		}
		// 如果是默认日期
		else {
			var type = a.split("_");
			var date = new Date();
			var oldDate = new Date();
			var year = date.getFullYear();// 年
			var month = date.getMonth() + 1;// 月
			var day = date.getDate();// 日
			var weekDay = date.getDay();// 星期几
			if (type[0] == "day") {
				dateType = "日";
				eDate = year + "-" + month + "-" + day;
				if (type[1] == "1") {
					sDate = year + "-" + month + "-" + day;
				} else if (type[1] == "7") {
					oldDate.setDate(oldDate.getDate() - 7);
					var oldMonth = oldDate.getMonth() + 1;
					sDate = oldDate.getFullYear() + "-" + oldMonth + "-"
							+ oldDate.getDate();
				} else if (type[1] == "14") {
					oldDate.setDate(oldDate.getDate() - 14);
					var oldMonth = oldDate.getMonth() + 1;
					sDate = oldDate.getFullYear() + "-" + oldMonth + "-"
							+ oldDate.getDate();
				} else if (type[1] == "30") {
					oldDate.setDate(oldDate.getDate() - 30);
					var oldMonth = oldDate.getMonth() + 1;
					sDate = oldDate.getFullYear() + "-" + oldMonth + "-"
							+ oldDate.getDate();
				}
			} else if (type[0] == "week") {
				dateType = "周";
				eDate = year + "-" + month + "-" + day;
				if (type[1] == "4") {
					oldDate.setDate(oldDate.getDate() - weekDay + 1 - 21);
					var oldMonth = oldDate.getMonth() + 1;
					sDate = oldDate.getFullYear() + "-" + oldMonth + "-"
							+ oldDate.getDate();
				} else if (type[1] == "8") {
					oldDate.setDate(oldDate.getDate() - weekDay + 1 - 56);
					var oldMonth = oldDate.getMonth() + 1;
					sDate = oldDate.getFullYear() + "-" + oldMonth + "-"
							+ oldDate.getDate();
				} else if (type[1] == "12") {
					oldDate.setDate(oldDate.getDate() - weekDay + 1 - 84);
					var oldMonth = oldDate.getMonth() + 1;
					sDate = oldDate.getFullYear() + "-" + oldMonth + "-"
							+ oldDate.getDate();
				}
			} else if (type[0] == "month") {
				dateType = "月";
				eDate = year + "-" + month;
				if (type[1] == "3") {
					if (month > 2) {
						var oldMonth = month - 2;
						sDate = year + "-" + oldMonth;
					} else {
						var oldYear = year - 1;
						var oldMonth = month + 10;
						sDate = oldYear + "-" + oldMonth;
					}
				} else if (type[1] == "6") {
					if (month > 5) {
						var oldMonth = month - 5;
						sDate = year + "-" + oldMonth;
					} else {
						var oldYear = year - 1;
						var oldMonth = month + 7;
						sDate = oldYear + "-" + oldMonth;
					}
				} else if (type[1] == "12") {
					if (month == 12) {
						var oldMonth = 1;
						sDate = year + "-" + oldMonth;
					} else {
						var oldYear = year - 1;
						var oldMonth = month + 1;
						sDate = oldYear + "-" + oldMonth;
					}
				}
			} else if (type[0] == "year") {
				dateType = "年";
				eDate = year;
				if (type[1] == "3") {
					sDate = year - 2;
				} else if (type[1] == "5") {
					sDate = year - 4;
				}
			}
		}
		// $('#dataDes').html(sDate + "~" + eDate + siteTitle + noteTitle);
	}
	if(a.split("_")[0] == "hour"){
		$('#dataDes').html(
				"<div>数据说明：" + noteTitle + dateType + "指标概览</div><div>时间范围："
						+ sDate  + "</div><div>场所名称：" + siteTitle
						+ "</div><div id='zhibiaomingcheng'></div>");
	}
	else{
	$('#dataDes').html(
			"<div>数据说明：" + noteTitle + dateType + "指标概览</div><div>时间范围："
					+ sDate + "~" + eDate + "</div><div>场所名称：" + siteTitle
					+ "</div><div id='zhibiaomingcheng'></div>");
}}

// 加载新table，2016年1月13日13:47:33
function showNewTable(result){
	$("#datatable").html(result);
	 $('#tabledata').dataTable({
// "scrollX": true,
// //添加横向滚动条
// "searching": false,
// //取消搜索
// //"bProcessing": true,
// //显示正在加载
// "bPaginate": true,
// "bLengthChange": false,
// "aaSorting": [
// [0, "desc"]
// ],
		// 默认第几个排序
		 "scrollX": true,// 添加横向滚动条
			"searching":false,// 取消搜索
			 "bProcessing": true,// 显示正在加载
			 "bPaginate": true   ,
			 "bLengthChange": false,
			"aaSorting": [[ 0, "asc" ]],// 默认第几个排序
			"bStateSave": false,// 状态保存
			"bRetrieve": true,
			"bAutoWidth": true,
// "aoColumnDefs": [
// // {"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
// {"orderable":false ,"aTargets":[0,5] }// 制定列不参与排序
// ],
		language: {
			"sProcessing": "处理中...",
			"sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
			"sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
			"sInfoFiltered": "(由 _MAX_ 项结果过滤)",
			"sInfoPostFix": "",
			"sUrl": "",
			"sEmptyTable": "表中数据为空",
			"sLoadingRecords": "载入中...",
			"sInfoThousands": ",",
			"oPaginate": {
				"sFirst": "首页",
				"sPrevious": "上页",
				"sNext": "下页",
				"sLast": "末页"
			},
			"oAria": {
				"sSortAscending": ": 以升序排列此列",
				"sSortDescending": ": 以降序排列此列"
			}
		}
	});
}
// 指标tip
 $(document).ready(function () {
    // 使用each（）方法来获得每个元素的属性
    $('img[src="images/ts.png"]').each(function () {
        $(this).qtip({
            content: {
                // 设置您要使用的文字图像的HTML字符串，正确的src URL加载图像
        		// text: '<img class="throbber" src="loading.gif"
				// alt="Loading..." />',
                url: "jsp/help.html", // 使用的URL加载的每个元素的rel属性
                title: {
                    text: $(this).attr("title"), // 给工具提示使用每个元素的文本标题
                    // button: '关闭' // 在标题中显示关闭文字按钮
                }
            },
            position: {
				// corner: {
					// target: 'bottomMiddle',
					// tooltip: 'topMiddle'
				// },
                corner: {  
                    tooltip: 'bottomLeft',  
                    target: 'topRight'  
                  },
                adjust: {
                    screen: true // 在任何时候都保持提示屏幕上的
                }
            },
            show: {
                when: 'mouseenter', // 或click
                solo: true // 一次只显示一个工具提示
            },
            hide: 'mouseout',
            style: {
                tip: true, // 设置一个语音气泡提示在指定工具提示角落的工具提示
                border: {
                    width: 0,
                    radius: 4
                },
                name: 'light', // 使用默认的淡样式
                width: 390 // 设置提示的宽度
            }
        })
    });
});
 
// 导出Excle getExportExcle，对于行数不太变化的小型table导出（url参数不能超过2000字节）
 function gailanExport(divName,divDescribe,fileName){
 	var character = "utf-8";
 	var mb = myBrowser();
 	if ("IE" == mb) {
 	}
 	if ("FF" == mb) {
 	   character =  "GB2312";
 	}
 	if ("Chrome" == mb) {
 	}
 	if ("Opera" == mb) {
 	}
 	if ("Safari" == mb) {
 	}
 	var testdate = new Date("yyyy,mth,dd,hh,mm,ss");
 	var date = new Date;
 	var today = timeFormat(date);
 	var table=$("#"+divName).val();
 	if(table==""||table==null){
 		alert("没有数据可以导出！");
 		return;
 	}
 	var fileName = fileName+today;
 	fileName = fileName.replace(/\s+/g,"");
 	fileName = fileName.replace("&","");
 	var describe = $("#"+divDescribe).html();
 	describe = describe.replace('&amp;','&');
 	describe = encodeURI(describe); 
 	table = encodeURI(table); 
 	fileName = encodeURI(fileName); 
 	$("#gailanExport").children("input[name='table']").val(table);
 	$("#gailanExport").children("input[name='fileName']").val(fileName);
 	$("#gailanExport").children("input[name='character']").val(character);
 	$("#gailanExport").children("input[name='describe']").val(describe);
 	$("#gailanExport").submit();
 }
 /*
	 * 格式化称yyyymtddhhmmss
	 */
 function timeFormat(date){
 	var year = date.getFullYear();
 	var month = (date.getMonth()+1);
 	var day = date.getDate();
 	var hour = date.getHours();
 	var minutes = date.getMinutes();
 	var seconds = date.getSeconds();
 	if (month<10) {
 		month = '0'+month
 	} else {
 		month = ''+month
 	}
 	if (day<10) {
 		day = '0'+day
 	} else {
 		day = ''+day
 	}
 	if (hour<10) {
 		hour = '0'+hour
 	} else {
 		hour = ''+hour
 	}
 	if (minutes<10) {
 		minutes = '0'+minutes
 	} else {
 		minutes = ''+minutes
 	}
 	if (seconds<10) {
 		seconds = '0'+seconds
 	} else {
 		seconds = ''+seconds
 	}
 	return year+month+day+hour+minutes+seconds
 } 
  
 function myBrowser(){
     var userAgent = navigator.userAgent; // 取得浏览器的userAgent字符串
     var isOpera = userAgent.indexOf("Opera") > -1;
     if (isOpera) {
         return "Opera"
     }; // 判断是否Opera浏览器
     if (userAgent.indexOf("Firefox") > -1) {
         return "FF";
     } // 判断是否Firefox浏览器
     if (userAgent.indexOf("Chrome") > -1){
   return "Chrome";
  }
     if (userAgent.indexOf("Safari") > -1) {
         return "Safari";
     } // 判断是否Safari浏览器
     if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
         return "IE";
     }; // 判断是否IE浏览器
 } 